using System.Collections.Generic;
using System.IO;

namespace ZerAx.TBON
{
    public class TbonIntArray : TbonObject
    {
        static TbonIntArray()
        {
            factories.Add(TbonType.IntArray, (s) => new TbonIntArray(s));
        }
        public override TbonType Type => TbonType.IntArray;

        public List<int> val = new();

        public TbonIntArray(string name) : base(name) { } 
        public TbonIntArray(string name, params int[] arr) : this(name)
        {
            val.AddRange(arr);
        }

        public override string GetValueString() => $"[{string.Join(',', val)}]";

        public override void ReadValue(BinaryReader reader)
        {
            val.Clear();
            var len = reader.ReadInt32();
            
            for (int i = 0; i < len; ++i)
            {
                val.Add(reader.ReadInt32());
            }
        }

        public override void WriteValue(BinaryWriter writer)
        {
            writer.Write(val.Count);
            for (int i = 0; i < val.Count; ++i)
            {
                writer.Write(val[i]);
            }
        }
    }
}